package com.neusoft.controller;

import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.resource.NoResourceFoundException;

import com.neusoft.exception.TokenException;
import com.neusoft.response.Result;

@CrossOrigin
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    public Result exception(Exception e) {
        e.printStackTrace();
        return Result.error();
    }

    @ExceptionHandler(TokenException.class)
    public Result tokenException(TokenException e) {
        e.printStackTrace();
        System.err.println("Token认证失败");
        return Result.tokenErr();
    }
    
    @ExceptionHandler(NoResourceFoundException.class)
    public Result noResourceFoundException(NoResourceFoundException e) {
        e.printStackTrace();
        return Result.notFoundErr(e.getMessage()); // 使用Result的notFoundErr方法返回404错误
    }
}
